#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(tansu, 0.2, TakashiC.Ito@gmail.com)
AC_CONFIG_AUX_DIR([config])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/tansu_log.c])
AC_CONFIG_HEADER([include/config.h])
AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [turn on debug flags]))
AC_ARG_ENABLE([gcov], AC_HELP_STRING([--enable-gcov], [turn on code coverage analysis tools]))
AC_ARG_ENABLE([gcc-warnings], AS_HELP_STRING([--enable-gcc-warnings], [enable verbose warnings with GCC]))
AC_ARG_ENABLE([gui-sample], AC_HELP_STRING([--enable-gui-sample], [enable GUI sample application]))
AC_ARG_ENABLE([cp-gena], AC_HELP_STRING([--enable-cp-gena], [enable control point GENA supprt]))

# Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AM_CONDITIONAL(GCC, test "$GCC" = yes)   # let the Makefile know if we're gcc
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_DISABLE_SHARED
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
PKG_PROG_PKG_CONFIG

if test "$GCC" = yes ; then
    CFLAGS="$CFLAGS -Wall"
fi

PKG_CHECK_MODULES(TINYDOM, tinydom)
PKG_CHECK_MODULES(LIBEVENT, libevent)

CFLAGS="$CFLAGS $TINYDOM_CFLAGS $LIBEVENT_CFLAGS"
CXXFLAGS="$CXXFLAGS $TINYDOM_CFLAGS $LIBEVENT_CFLAGS"
LIBS="$LIBS $TINYDOM_LIBS $LIBEVENT_LIBS"

# Checks for libraries.
if test "x$cross_compiling" = "xno"; then
    AC_CHECK_LIB(expat, XML_Parse, , AC_MSG_ERROR(expat not found))
    AC_CHECK_LIB(event, evbuffer_add_printf, , AC_MSG_ERROR(libevent not found))
    AC_CHECK_LIB(tdom, tdom_elem_new, , AC_MSG_ERROR(libtdom not found))
else
    AC_CHECK_LIB(expat, XML_Parse)
    AC_CHECK_LIB(event, evbuffer_add_printf)
    AC_CHECK_LIB(tdom, tdom_elem_new)
fi

LIBS="$LIBS -lexpat"

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stdint.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([string.h])
AC_CHECK_HEADERS([stdarg.h])
AC_CHECK_HEADERS([errno.h])
AC_CHECK_HEADERS([time.h])
AC_CHECK_HEADERS([assert.h])
AC_CHECK_HEADERS([fcntl.h])
AC_CHECK_HEADERS([unistd.h])
AC_CHECK_HEADERS([ifaddrs.h])
AC_CHECK_HEADERS([sys/un.h])
AC_CHECK_HEADERS([sys/types.h])
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([sys/queue.h])
AC_CHECK_HEADERS([sys/ioctl.h])
AC_CHECK_HEADERS([netinet/in.h])
AC_CHECK_HEADERS([arpa/inet.h])
AC_CHECK_HEADERS([net/if.h])
AC_CHECK_HEADERS([expat.h])
AC_CHECK_HEADERS([event.h])
AC_CHECK_HEADERS([evutil.h])
AC_CHECK_HEADERS([evhttp.h])
AC_CHECK_HEADERS([tdom.h])
AC_CHECK_HEADERS([tdom_writer.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([clock_gettime])
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([memset])
AC_CHECK_FUNCS([socket])
AC_CHECK_FUNCS([strcasecmp])
AC_CHECK_FUNCS([strncasecmp])
AC_CHECK_FUNCS([strdup])
AC_CHECK_FUNCS([strndup])
AC_CHECK_FUNCS([strstr])
AC_CHECK_FUNCS([strchr])
AC_CHECK_FUNCS([strrchr])
AC_CHECK_FUNCS([strsep])
AC_CHECK_FUNCS([strspn])
AC_CHECK_FUNCS([strtol])
AC_CHECK_FUNCS([strtoul])
AC_CHECK_FUNCS([localtime_r])

# Check for --enable-debug and add appropriate flags for gcc
if test "x$enable_debug" = "xyes"; then
    CFLAGS="$CFLAGS -g -O0 -DTANSU_DEBUG"
fi

# Check for --enable-gcov and add appropriate flags for gcc
if test "x$enable_gcov" = "xyes"; then
    CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
fi

# Check for --enable-gui-sample
if test "x$enable_gui_sample" = "xyes"; then
    AM_PROG_CC_C_O
    TANSU_GUI_APP="ssdp dacp light"
    AC_SUBST(TANSU_GUI_APP)
    AC_CONFIG_FILES([sample/ssdp/Makefile])
    AC_CONFIG_FILES([sample/dacp/Makefile])
    AC_CONFIG_FILES([sample/light/Makefile])
    #PKG_CHECK_MODULES(DIRECTFB, [directfb])
fi

# Check for --enable-cp-gena and add appropriate flags for gcc
if test "x$enable_cp_gena" = "xyes"; then
    CFLAGS="$CFLAGS -DTANSU_CP_ENABLE_GENA"
    CXXFLAGS="$CXXFLAGS -DTANSU_CP_ENABLE_GENA"
fi

AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([tansu.pc])
AC_CONFIG_FILES([test/Makefile])
AC_CONFIG_FILES([sample/Makefile])

AC_OUTPUT

